#include "UdpServer.hpp"
#include <iostream>
#include <memory>
#include "InetAddr.hpp"
#include "ThreadPool.hpp"
#include "Log.hpp"
#include "Route.hpp"

using namespace ThreadPoolModule;
using namespace LogModule;
using task_t = std::function<void()>;
int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;//使用格式不正确
    }
    Enable_Console_Log_Strategy();  
    uint16_t port = std::stoi(argv[1]);
    Route r;
    auto tp = ThreadPool<task_t>::GetInstance();
    std::unique_ptr<Server> s = std::make_unique<Server>(port, [&r, &tp](int sockfd, const std::string &message, Inet_Addr& peer){
         task_t t = std::bind(&Route::Message, &r, sockfd, message, peer);
         tp->Enqueue(t);
    });
    s -> Init();
    s -> Start();
    return 0;
}
